//
//  KZMapViewController.m
//  xiaorizi
//
//  Created by kun on 15/11/1.
//  Copyright © 2015年 origin. All rights reserved.
//

#import "KZMapViewController.h"


//添加本地定位
#import <CoreLocation/CoreLocation.h>

//添加地图map
#import <MapKit/MapKit.h>
#import "UIViewAdditions.h"
#import "UserMapView.h"

@interface KZMapViewController ()<CLLocationManagerDelegate>

//用户位置定位
@property (nonatomic,strong) CLLocationManager *locationManger;

@property (nonatomic,weak)UserMapView *useMapView;



@end

@implementation KZMapViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self createLocationManger];
    
    [self createMapKit];
    
    
}


//2 添加个人位置定位Map
-(void) createMapKit
{
    
    UserMapView *view = [UserMapView userMapView];
    view.frame = CGRectMake(0, 0, self.view.width, self.view.height - 64);
    [self.view addSubview:view];
    _useMapView = view;
    _useMapView.model = _model;
}

-(void)createLocationManger
{
    //查看是否打开地图定位
    if(![CLLocationManager locationServicesEnabled])
    {
        NSLog(@"Location Service Not Enabled");
        return;
    }
    self.locationManger = [CLLocationManager new];
    
    //设置定位精确度 移动多少时候定位更新
    //self.locationManger.distanceFilter = 10;
    
    if([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined)
    {
        [self.locationManger requestWhenInUseAuthorization];
    }
    
    self.locationManger.delegate = self;
    
    //开启定位
    [self.locationManger startUpdatingLocation];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
